package ru.rchervot.sanasar.client.view;

import ru.rchervot.sanasar.client.model.FactoryQueryCandidates;
import ru.rchervot.sanasar.client.model.filters.FilterFullText;
import ru.rchervot.sanasar.client.model.filters.FilterItemIds;
import ru.rchervot.sanasar.client.rpc.RPCServiceAsync;

import com.google.gwt.event.shared.HandlerManager;
import com.google.gwt.user.client.ui.Widget;
import com.google.inject.Inject;


public class FactoryFiltersPanelViewCandidates extends AbstractFactoryFiltersPanelView {
	
	@Inject
	public FactoryFiltersPanelViewCandidates(
			HandlerManager eventBus, RPCServiceAsync service,
			FactoryQueryCandidates factoryQuery) {
		super(eventBus, service, factoryQuery);
		
		allFiltersNames.add("");
		allFiltersNamesHuman.add("");
		
		orderByItems.add("Name (a-z)");
		orderByItems.add("Name (z-a)");
		orderByItems.add("Age (a-z)");
		
		matchItems.add("all of the conditions"); 
		matchItems.add("any of the conditions"); 
		
		addFilter(getFilterItemIdView());
		addFilter(getFilterFullTextView());
	}

	private FilterFullTextView getFilterFullTextView() {
		FilterFullTextView v = new FilterFullTextView(FilterFullText.NAME, "Full Text");
		FilterFullTextPresenter p = new FilterFullTextPresenter(v, eventBus);
		p.bindDisplay();
		
		return v;
	}
	
	private FilterItemIdView getFilterItemIdView() {
		FilterItemIdView v = new FilterItemIdView(FilterItemIds.NAME, "Items IDs");
		FilterItemIdPresenter p = new FilterItemIdPresenter(v, eventBus);
		p.bindDisplay();
		
		return v;
	}
	
	private void addFilter(AbstractFilterView filterView) {
		allFiltersNames.add(filterView.getFilterName());
		allFiltersNamesHuman.add(filterView.getFilterNameHuman());
		filtersViews.add(filterView);
	}
	
	@Override
	public Widget getFiltersPanelView() {
		FiltersPanelCandidatesPresenter.Display v = new FiltersPanelCandidatesView(
				allFiltersNames, allFiltersNamesHuman,
				orderByItems, matchItems, filtersViews);
		FiltersPanelCandidatesPresenter p = new FiltersPanelCandidatesPresenter(v, eventBus, service, factoryQuery);
		p.bindDisplay();
		
		return (Widget)v;
	}
	
}
